import sys
from PyQt5.QtWidgets import QSlider, QApplication, QVBoxLayout, QHBoxLayout, QWidget, QLabel
from PyQt5.QtCore import Qt

class TrackingModeDemo(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()
        self.setup_tracking_comparison()
    
    def setup_ui(self):
        layout = QVBoxLayout()
        
        # 实时跟踪模式
        self.realtime_slider = QSlider(Qt.Horizontal)
        self.realtime_slider.setRange(0, 100)
        self.realtime_slider.setTracking(True)  # 默认值
        self.realtime_slider.valueChanged.connect(
            lambda v: print(f"实时跟踪: {v}")
        )
        
        # 非跟踪模式
        self.non_tracking_slider = QSlider(Qt.Horizontal)
        self.non_tracking_slider.setRange(0, 100)
        self.non_tracking_slider.setTracking(False)
        self.non_tracking_slider.valueChanged.connect(
            lambda v: print(f"非跟踪模式: {v}")
        )
        
        layout.addWidget(QLabel("实时跟踪模式 (默认):"))
        layout.addWidget(self.realtime_slider)
        layout.addWidget(QLabel("非跟踪模式:"))
        layout.addWidget(self.non_tracking_slider)
        
        self.setLayout(layout)
    
    def setup_tracking_comparison(self):
        # 演示两种模式的区别
        print("拖动实时跟踪滑块会在移动过程中持续输出值")
        print("拖动非跟踪滑块只会在释放时输出最终值")



if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = TrackingModeDemo()
    window.show()
    sys.exit(app.exec_())